package face.pay.common.enterprise.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import face.pay.common.enterprise.service.IMchAgencyInfoService;
import face.pay.common.enterprise.service.ITerminalTargetAllCountService;
import face.pay.dao.TerminalTargetAllCountDao;
import face.pay.entity.MchAgencyInfo;
import face.pay.entity.TerminalTargetAllCount;
import face.pay.entity.UserInfo;
import face.pay.util.page.PageData;
import face.pay.util.page.PageParam;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @Classname TerminalTargetOnCountServiceImpl
 * @Description JJL
 * @Date 2019/10/24 13:51
 */
@Service
@Slf4j
public class TerminalTargetAllCountServiceImpl implements ITerminalTargetAllCountService {

    @Autowired
    private TerminalTargetAllCountDao targetAllCountDao;

    /**
     * 统计代理商下所有商家收入
     *
     * @param loginInfo
     * @return
     */
    @Override
    public PageData queryAllCount(UserInfo loginInfo, PageParam pageParam,String sn,String mchUserName) {
        PageHelper.startPage(pageParam.getPageNo(), pageParam.getPageSize());

        if ("ENTERPRISE".equals(loginInfo.getType())) { //商家设备查询

            List<TerminalTargetAllCount> orderInfos = targetAllCountDao.queryMchAllTarget(loginInfo.getId(),loginInfo.getOemId(),sn);

            PageInfo<TerminalTargetAllCount> pageInfo = new PageInfo<>(orderInfos);

            PageData<TerminalTargetAllCount> pageData = new PageData<>(pageInfo.getTotal(), orderInfos);

            return pageData;

        }else{ //代理商查询商家设备

            List<TerminalTargetAllCount> orderInfos = targetAllCountDao.queryAgencyAllTarget(loginInfo.getId(),loginInfo.getOemId(),mchUserName,sn);

            PageInfo<TerminalTargetAllCount> pageInfo = new PageInfo<>(orderInfos);

            PageData<TerminalTargetAllCount> pageData = new PageData<>(pageInfo.getTotal(), orderInfos);

            return pageData;
        }

    }

}
